package cn.bob.basic.controller;

import cn.bob.basic.dto.LoginDto;
import cn.bob.basic.dto.RegisterDto;
import cn.bob.basic.dto.WechatDto;
import cn.bob.basic.service.ILoginService;
import cn.bob.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author bob
 * @data 2022/10/21-11:52
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    //手机用户名邮箱登录
    @PostMapping("/account")
    public AjaxResult account(@RequestBody LoginDto loginDto){
        //将生成的token与用户信息拼接到一起返回给前端
        Map<String,Object> map = loginService.account(loginDto);
        return  AjaxResult.me().success(map);
    }
    //手机验证码登录
    @PostMapping("/smsCodeAccount")
    public AjaxResult smsCodeLoginaccount(@RequestBody RegisterDto smsCodeLoginDto){
        //将生成的token与用户信息拼接到一起返回给前端
        Map<String,Object> map = loginService.smsCodeLoginaccount(smsCodeLoginDto);
        return  AjaxResult.me().success(map);
    }
    //微信扫码登录有用户直接登录
    @PostMapping("/wechat")
    private AjaxResult wechat(@RequestBody WechatDto wechatDto){
        return loginService.wechat(wechatDto);

    }
    //微信扫码用户绑定的接口
    @PostMapping("/wechat/binder")
    private AjaxResult wechatbinder(@RequestBody WechatDto wechatDto){
        Map<String, Object> map = loginService.wechatbinder(wechatDto);
        return AjaxResult.me().success(map);
    }




}
